package concurrency;

import java.util.concurrent.TimeUnit;

class ChassisBuilder implements Runnable {
    private CarQueue mCarQueue;

    private int mCounter = 0;

    public ChassisBuilder(CarQueue cq) {
        mCarQueue = cq;
    }

    @Override
    public void run() {
        try {
            while (!Thread.interrupted()) {
                TimeUnit.MILLISECONDS.sleep(500);
                // Make chassis
                Car c = new Car(mCounter++);
                System.out.println("ChassisBuilder created " + c);
                // Insert into queue
                mCarQueue.put(c);
            }
        } catch (InterruptedException e) {
            System.out.println("Interrupted: ChassisBuilder");
            // e.printStackTrace();
        }
        System.out.println("ChassisBuilder off");
    }
}
